# -*- coding: utf8 -*-

def format_as_http_date(date):
    """ Formats a date like 'Tue, 15 Nov 1994 12:45:26 GMT'

    See RFC 2616 section 14.29 
    http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
    """
    return date.strftime('%a, %d %b %Y %H:%M:%S GMT')


class MultiValueDict(dict):
    """ Dictionary which can contain multiple values for each key. """
    
    def __setitem__(self, key, value):
        self.setdefault(key, []).insert(0, value)

    def __getitem__(self, key):
        """ Returns the last inserted value for the key. """
        return super(MultiValueDict, self).__getitem__(key)[0]

    def get_all(self, key):
        """ Returns a list with all values for the key. """
        return super(MultiValueDict, self).__getitem__(key)


